﻿using System;

namespace Sencha.Serialization.Serializers
{
	public sealed class UriSerializer : TypeSerializer<Uri>
	{
		public override Uri Deserialize(IJsonReader reader)
		{
			if (reader.Token == JsonToken.Null)
				return null;
			
			var uriStr = reader.ReadString(false);
			var value = new Uri(uriStr);
			return value;
		}
		public override void Serialize(IJsonWriter writer, Uri value)
		{
			if (value == null)
				writer.WriteNull();
			else
				writer.WriteString(value.ToString());
		}
	}
}
